import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class YRecommend extends StatelessWidget {
  List recommendList;

  YRecommend({Key key, this.recommendList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenUtil().setHeight(380),
      margin: EdgeInsets.only(top: 12.0),
      child: SingleChildScrollView(
        physics: new NeverScrollableScrollPhysics(),
        child: Column(
          children: <Widget>[_titleWidget(), _recommedList()],
        ),
      ),
    );
  }

  /*头部布局*/
  Widget _titleWidget() {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.fromLTRB(10.0, 2.0, 0.0, 5.0),
      decoration: BoxDecoration(
          color: Colors.white,
          border:
              Border(bottom: BorderSide(width: 0.5, color: Colors.black12))),
      child: Text("商品推荐", style: TextStyle(color: Colors.pink)),
    );
  }

  /*商品单独项方法*/
  Widget _item(index) {
    return InkWell(
      onTap: () {},
      child: Container(
        height: ScreenUtil().setHeight(330),
        width: ScreenUtil().setHeight(250),
        padding: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
            color: Colors.white,
            border:
                Border(right: BorderSide(width: 0.5, color: Colors.black12))),
        child: Column(
          children: <Widget>[
            Image.network(recommendList[index]['image']),
            Text("￥ ${recommendList[index]['mallPrice']}"),
            Text(
              "￥ ${recommendList[index]['price']}",
              style: TextStyle(
                  //加上删除线
                  decoration: TextDecoration.lineThrough,
                  color: Colors.grey),
            )
          ],
        ),
      ),
    );
  }

  /*横向列表*/

  Widget _recommedList() {
    return Container(
      height: ScreenUtil().setHeight(330),
      child: ListView.builder(
        itemCount: recommendList.length,
        itemBuilder: (context, index) {
          return _item(index);
        },
        //设置横向的
        scrollDirection: Axis.horizontal,
      ),
    );
  }
}
